package com.lushu.data {
import com.lushu.data.interfaces.ITreeProvider;
import com.lushu.info.ApplicationData;
import com.sfdk.events.IOEvent;
import com.sfdk.io.GenericIO;

import flash.events.Event;
import flash.events.EventDispatcher;

public class ZoneInfo extends EventDispatcher implements ITreeProvider {
    private var name_:String;
    private var ioUtil_:GenericIO;

    private var zoneData_:XML;

    public function ZoneInfo(mapName:String) {
        name_ = mapName;
        if (name_.split(".").length == 1)
            ioUtil_ = new GenericIO(ApplicationData.BASE_LOCATION + "/" + ApplicationData.ZONE_DIRECTORY + "/" + name_ + ".map");
        else
            ioUtil_ = new GenericIO(ApplicationData.BASE_LOCATION + "/" + ApplicationData.ZONE_DIRECTORY + "/" + name_);
        ioUtil_.addEventListener(IOEvent.LOAD_COMPLETE, parseTilesetData);
        ioUtil_.read(GenericIO.XML_FILE);
    }

    private function parseTilesetData(event:IOEvent):void {
        zoneData_ = ioUtil_.getFileData();

        dispatchEvent(new Event("zoneLoaded"));
    }

    public function getData():XML {
        return zoneData_;
    }

    public function getName():String {
        return name_;
    }

    public function get label():String {
        return name_;
    }
}
}